﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using GuoShuCan.SDK.Web;
using GuoShuCan.SDK.Web.Globalization;
using GuoShuCan.SDK.Web.ServerControls.Manage;
public partial class Manage_Management : System.Web.UI.UserControl, IManageMaster, IEditControl, IUpdateCulture, ILoadMenuID
{
    #region ILoadMenuID
    string ILoadMenuID.MenuID
    {
        get
        {
            return "ListManagement";
        }
    }
    #endregion
    #region IUpdateCulture
    /// <summary>
    /// 更新区域接口。
    /// </summary>
    void IUpdateCulture.UpdateCulture()
    {
        //更新子控件区域接口。
        foreach (Control item in Edit.Controls)
        {
            //更新使用区域更新接口控件。
            if (item is IUpdateCulture)
            {
                ((IUpdateCulture)item).UpdateCulture();
            }
        }
        //更新子控件区域接口。
        foreach (Control item in List.Controls)
        {
            //更新使用区域更新接口控件。
            if (item is IUpdateCulture)
            {
                ((IUpdateCulture)item).UpdateCulture();
            }
        }
    }
    #endregion
    #region IEditControl 创建列表对象编辑控件接口
    /// <summary>
    /// 获取编辑的控件对象容器。
    /// </summary>
    PlaceHolder IEditControl.EditPlaceHolder
    {
        get
        {
            return this.Edit;
        }
    }
    /// <summary>
    /// 获取列表的控件对象容器。
    /// </summary>
    PlaceHolder IEditControl.ListPlaceHolder
    {
        get
        {
            return this.List;
        }
    }
    /// <summary>
    /// 
    /// </summary>
    Control IEditControl.LoadEditControl(string control)
    {
        this.Edit.Controls.Clear();
        this.ViewState["EditControl"] = control;
        Control editControl = this.LoadControl(control);
        editControl.ID = "EditControl";
        if (editControl is IManageMaster)
        {
            ((IManageMaster)editControl).Master = _master;
        }
        if (editControl is ISetIEditControl)
        {
            ((ISetIEditControl)editControl).EditControl = this;
        }
        this.Edit.Controls.Add(editControl);
        this.up.Update();
        return editControl;
    }
    /// <summary>
    /// 
    /// </summary>
    void IEditControl.UninstallEditControl()
    {
        this.ViewState["EditControl"] = null;
        this.Edit.Controls.Clear();
        this.up.Update();
    }
    /// <summary>
    /// 获取更新控件对象。
    /// </summary>
    UpdatePanel IEditControl.EditUpdatePanel
    {
        get
        {
            return this.up;
        }
    }
    /// <summary>
    /// 获取更新控件对象。
    /// </summary>
    UpdatePanel IEditControl.ListUpdatePanel
    {
        get
        {
            return this.up;
        }
    }
    /// <summary>
    /// 
    /// </summary>
    object IEditControl.Tag
    {
        get
        {
            return this.ViewState;
        }
    }
    #endregion
    #region IManageMaster
    /// <summary>
    /// 
    /// </summary>
    Master _master = null;
    /// <summary>
    /// 
    /// </summary>
    Master IManageMaster.Master
    {
        set
        {
            _master = value;
        }
        get
        {
            return _master;
        }
    }
    #endregion
    Control _editList;
    /// <summary>
    /// 
    /// </summary>
    /// <param name="e"></param>
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        //
        this.List.Controls.Clear();
        _editList = this.LoadControl("ListManage.ascx");
        _editList.ID = "EditList";
        if (_editList is IManageMaster)
        {
            ((IManageMaster)_editList).Master = _master;
        }
        if (_editList is ISetIEditControl)
        {
            ((ISetIEditControl)_editList).EditControl = this;
        }
        this.List.Controls.Add(_editList);
        this.Edit.Controls.Clear();
    }
    /// <summary>
    /// 
    /// </summary>
    /// <param name="e"></param>
    protected override void OnLoad(EventArgs e)
    {
        if (this.IsPostBack)
        {
            //验证是否存在编辑控件。
            if (this.ViewState["EditControl"] != null)
            {
                Control editControl = this.LoadControl(this.ViewState["EditControl"].ToString());
                editControl.ID = "EditControl";
                if (editControl is IManageMaster)
                {
                    ((IManageMaster)editControl).Master = _master;
                }
                if (editControl is ISetIEditControl)
                {
                    ((ISetIEditControl)editControl).EditControl = this;
                }
                this.Edit.Controls.Add(editControl);
                this.up.Update();
            }
        }
        base.OnLoad(e);
    }
    /// <summary>
    /// 
    /// </summary>
    /// <param name="e"></param>
    protected override void OnPreRender(EventArgs e)
    {
        if (this.Edit.Controls.Count == 0)
        {
            this.List.Visible = true;
        }
        else
        {
            this.List.Visible = false;
        }
        base.OnPreRender(e);
    }
}